package com.jdd.modules.people.model;

import com.jdd.dao.entity.TArea;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 区域 存储树结构数据的实体类
 * <p>
 *
 * @Author Steve
 * @Since 2019-01-22
 */
@Data
public class TAreaTreeModel implements Serializable{

    private static final long serialVersionUID = 1L;

    /** 对应Area中的id字段,前端数据树中的key*/
    private String key;

    /** 对应Area中的id字段,前端数据树中的value*/
    private String value;

    /** 对应Area.name字段,前端数据树中的title*/
    private String title;


    private boolean isLeaf;
    // 以下所有字段均与SysDepart相同
    private String id;

    private String name;

    private Integer level;

    private Integer sort;

    private LocalDateTime createTime;

    private LocalDateTime updateTime;

    private String createUser;

    private String updateUser;

    private String parentId;

    private Integer status;

    private String areaCode;

    private String remark;

    private List<TAreaTreeModel> children = new ArrayList<>();


    /**
     * 将TArea对象转换成TAreaTreeModel对象
     * @param tArea
     */
	public TAreaTreeModel(TArea tArea) {
		this.key = tArea.getId().toString();
        this.value = tArea.getId().toString();
        this.title = tArea.getName();
        this.id = tArea.getId();
        this.parentId = tArea.getParentId();
        this.name = tArea.getName();
        this.level = tArea.getLevel();
        this.sort = tArea.getSort();
        this.createTime = tArea.getCreateTime();
        this.updateTime = tArea.getUpdateTime();
        this.createUser = tArea.getCreateUser();
        this.status = tArea.getStatus();
        this.updateUser = tArea.getUpdateUser();
        this.remark = tArea.getRemark();
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public boolean getIsLeaf() {
        return isLeaf;
    }

    public void setIsLeaf(boolean leaf) {
        isLeaf = leaf;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public TAreaTreeModel() { }

    /**
     * 重写equals方法
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
			return true;
		}
        if (o == null || getClass() != o.getClass()) {
			return false;
		}
        TAreaTreeModel model = (TAreaTreeModel) o;
        return Objects.equals(id, model.id) &&
                Objects.equals(parentId, model.parentId) &&
                Objects.equals(name, model.name) &&
                Objects.equals(level, model.level) &&
                Objects.equals(sort, model.sort) &&
                Objects.equals(createTime, model.createTime) &&
                Objects.equals(updateTime, model.updateTime) &&
                Objects.equals(createUser, model.createUser) &&
                Objects.equals(status, model.status) &&
                Objects.equals(updateUser, model.updateUser) &&
                Objects.equals(areaCode, model.areaCode) &&
                Objects.equals(remark, model.remark) &&
                Objects.equals(children, model.children);
    }

    /**
     * 重写hashCode方法
     */
    @Override
    public int hashCode() {

        return Objects.hash(id, parentId, name, level, sort,
                createTime, updateTime, createUser, status, updateUser, areaCode, remark, children);
    }

}
